package Hot100.Greedy_algorithm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class maxProfit {
    public static void main(String[] args) {
        int[] nums = {7,1,5,3,6,4};
        System.out.println(new maxProfit().maxProfit(nums));
    }
    public int maxProfit(int[] prices) {

        int min_price = prices[0];
        int max_profit = 0;
        for (int i = 1; i < prices.length; i++) {
            if(max_profit < prices[i] - min_price){
                max_profit = prices[i] - min_price;
            }
            if(min_price > prices[i]){
                min_price = prices[i];
            }
        }
        return max_profit;
    }
}

